# -*- coding: utf-8; mode: tcl; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- vim:fenc=utf-8:ft=tcl:et:sw=4:ts=4:sts=4

PortSystem          1.0
PortGroup           compiler_blacklist_versions 1.0
PortGroup           muniversal 1.0

name                libvpx
version             1.8.2
categories          multimedia
maintainers         {devans @dbevans} openmaintainer
platforms           darwin
license             Permissive

description         WebM VP8/VP9 Codec SDK
long_description    The WebM VP8/VP9 codecs are being developed \
                    specifically to meet the demand for the consumption \
                    of video over the Internet, including professionally \
                    and amateur produced video-on-demand and conversational \
                    video content. VP9 is an evolution of the VP8 video \
                    codec and includes a number of enhancements and new \
                    coding tools that have been added to improve coding efficiency. \
                    The VP9 encoder in this release is not, as yet, feature complete.

homepage            http://webmproject.org/tools/

# use git fetch rather than downloading a snapshot tarball
# which delivers a different checksum and size on each download
# this is not a stealth upgrade but a "feature" of this repo

fetch.type          git
git.url             https://chromium.googlesource.com/webm/${name}
git.branch          v${version}

# support for non-intel archs removed in version 1.5.0
supported_archs     x86_64 i386

depends_build-append port:yasm

patchfiles          patch-build-make-configure.sh.diff \
                    patch-Makefile.diff

# clang 425.0.28 with libvpx-1.4.0:
# vp9/common/x86/vp9_subpixel_8t_intrin_avx2.c:77:16: error: assigning to '__m256i' from incompatible type 'int'
#  filtersReg32 = MM256_BROADCASTSI128_SI256(filtersReg);
#               ^ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# apple gcc-4.2 with libvpx-1.6.0:
# vp9/encoder/x86/vp9_frame_scale_ssse3.c: In function ‘eight_tap_row_ssse3’:
# vp9/encoder/x86/vp9_frame_scale_ssse3.c:93: internal compiler error: Segmentation fault
# {standard input}:unknown:Undefined local symbol LC2

compiler.blacklist  *gcc-3.* *gcc-4.* {clang < 800} macports-clang-3.3 macports-clang-3.4 macports-clang-3.7
# Make sure that mp-clang-5.0 is picked if all compilers were blacklisted.
# Especially important for 10.6 on libc++, since the fallback list contains macports-clang-3.7
# as the first, and thus selected, fallback option (even though it has been blacklisted earlier).
compiler.fallback-append macports-clang-5.0 macports-clang-6.0 macports-clang-7.0 macports-clang-8.0

license_noconflict  clang-5.0 clang-6.0 clang-7.0

# As of 1.7.0: builds both static and shared libraries
# doesn't install docs or examples correctly, so disable them.
configure.args      --enable-vp8 \
                    --enable-vp9 \
                    --enable-internal-stats \
                    --enable-pic \
                    --enable-postproc \
                    --enable-multithread \
                    --enable-runtime-cpu-detect \
                    --enable-experimental \
                    --enable-shared \
                    --disable-install-docs \
                    --disable-debug-libs \
                    --disable-examples \
                    --disable-unit-tests

configure.env       LD=${configure.cc}

# add in when docs are installed correctly
#variant docs description {Build documentation} {
#    depends_build-append path:bin/php:php5 port:doxygen
#    configure.args-delete --disable-install-docs
#    configure.args-append --enable-install-docs
#}

build.target
build.args          verbose=1

destroot.args       verbose=1

# Build fix for MacPorts clang-3.5 and later:
#
# This is an intentional change to Clang. It now parses the assembly output by default even when emitting assembly so that the diagnostics are consistent between "clang -c" and "clang -S".
# The solution is either to pass -fno-integrated-as to the compiler, or change the assembly produced (& probably the script that processes it) so that it's valid. Note that commenting out the line won't work: comments get stripped by the same process.
# Current Xcode versions of clang > 602 corresponding to Xcode 6.3 or greater also need this fix.

if {[string match {macports-clang-3.[5-9]} ${configure.compiler}] ||
    [string match {macports-clang-[4-9].*} ${configure.compiler}] ||
    [string match {macports-clang-[1-9][0-9].*} ${configure.compiler}] ||
    (${configure.compiler} eq "clang" && [compiler.command_line_tools_version ${configure.compiler}] > 602)} {
        build.args-append CFLAGS_S=-fno-integrated-as
}

configure.universal_args-delete --disable-dependency-tracking

# As of 1.5.0 ppc build targets are no longer supported

set my_targets(i386)    x86
set my_targets(x86_64)  x86_64

# We must specify the target, otherwise the configure script will guess,
# and that may not match what the user requested in macports.conf.
foreach my_arch {i386 x86_64} {
    set merger_host(${my_arch}) ""
    if {[info exists my_targets(${my_arch})]} {
        set merger_configure_args(${my_arch}) --force-target=$my_targets(${my_arch})-${os.platform}-gcc
    }
}
if {![variant_isset universal]} {
    if {[info exists merger_configure_args(${build_arch})]} {
        configure.args-append $merger_configure_args(${build_arch})
    } else {
        configure.args-append --force-target=${os.arch}-${os.platform}-gcc
    }
}

# shared library uses relative path in install name
# override with absolute path
post-destroot {
    set libname ${prefix}/lib/${name}.6.dylib
    system "install_name_tool -id ${libname} ${destroot}${libname}"
}

livecheck.type  regex
livecheck.url   https://chromium.googlesource.com/webm/${name}
livecheck.regex ">v(\\d+(?:\\.\\d+)*)<"
